/*
 * PassagemUI.java
 *
 * Created on 09/10/2011, 20:07:51
 */
package com.bcc.airlines.ui;

import com.bcc.airlines.patterns.Observador;
import com.bcc.airlines.app.Facade;
import com.bcc.airlines.domain.Passageiro;
import com.bcc.airlines.domain.Passagem;
import com.bcc.airlines.domain.Voo;
import com.bcc.airlines.ui.effects.TextFieldEffects;
import com.bcc.airlines.util.Tupla;
import java.awt.Color;
import java.awt.event.KeyEvent;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Serginho
 */
public class TicketUI extends javax.swing.JPanel implements Observador {

    public TicketUI(MainUI main) {
        this.main = main;
        initComponents();

        main.getFachada().registerDatabaseObserver(this);
        atualiza();
    }

    @Override
    public void atualiza() {
        updateTable();
    }

    /**
     * Atualiza a tabela
     */
    private void updateTable() {
        // Pede a fachada uma lista de voos cadastrados no sistema
        Facade fachada = main.getFachada();
        List<Voo> voos = fachada.<Voo>list(Voo.class);

        // Pega o modelo da tabela que atualiza os dados
        DefaultTableModel model = (DefaultTableModel) flightsTable.getModel();

        // utilidade para datas
        DateFormat fmt = DateFormat.getDateInstance(DateFormat.MEDIUM);

        // Se a lista de voos nao estiver vazia
        if (voos != null && !voos.isEmpty()) {

            // Apaga tudinho
            for (int i = model.getRowCount() - 1; i >= 0; i--) {
                model.removeRow(i);
            }

            for (Voo v : voos) {
                Object row[] = new Object[7];
                row[0] = v.getIdVoo();
                row[1] = v.getAeronave().getNome();
                row[2] = fmt.format(v.getSaida());
                row[3] = v.getAeroportoByOrigem().getNome();
                row[4] = v.getAeroportoByDestino().getNome();
                row[6] = String.valueOf(v.getPassagems().size());
                model.addRow(row);
            }
        }

        clearFields();
    }

    /**
     * Procura por um voo pelo seu destino no banco da aplicacao
     *
     * @param destino
     */
    public void searchAndShow(String destino) {
        Facade fachada = main.getFachada();
        Voo v = fachada.<Voo>get(Voo.class, destino);

        // utilidade para datas
        DateFormat fmt = DateFormat.getDateInstance(DateFormat.MEDIUM);

        // Pega o modelo da tabela que atualiza os dados
        DefaultTableModel model = (DefaultTableModel) flightsTable.getModel();

        // Se o voo for nulo
        if (v != null) {

            // Apaga tudinho
            for (int i = model.getRowCount() - 1; i >= 0; i--) {
                model.removeRow(i);
            }

            Object row[] = new Object[6];
            row[0] = v.getIdVoo();
            row[1] = v.getAeronave().getNome();
            row[2] = fmt.format(v.getSaida());
            row[3] = v.getAeroportoByOrigem().getNome();
            row[4] = v.getAeroportoByDestino().getNome();
            model.addRow(row);
        }
    }

    /**
     * Submete o pedido de venda do ticket
     */
    private void submit() {
        Facade fachada = main.getFachada();

        Voo v = fachada.get(Voo.class, flightNumberTextField.getText().trim());
        String nome = nameTextField.getText().trim();
        String cpf = cpfTextField.getText().trim();

        // Adiciona o passageiro a base de dados da empresa. Caso exista, ele ignora isso
        Passageiro p = new Passageiro(cpf, nome, "", "", new HashSet<Passagem>(0));
        fachada.<Passageiro>add(Passageiro.class, p);

        // Cria um objeto ticket que sera completado e passado para validacao 
        // na classe PassagemManager
        Passagem t = new Passagem(0, v, p);

        // Adiciona o ticket atual na lista de tickets do passageiro
        p.getPassagems().add(t);

        // Manda a fachada cuidar do resto do processo
        fachada.<Passagem>add(Passagem.class, t);

        updateTable();
    }

    /**
     * Carrega a lista de passageiros do voo ao clicar na tabela
     */
    private void loadPassengersTable() {
        int linha = flightsTable.getSelectedRow();

        Facade fachada = main.getFachada();
        String id = (String) flightsTable.getModel().getValueAt(linha, 0);
        Voo v = fachada.<Voo>get(Voo.class, id);

        DefaultTableModel model = (DefaultTableModel) passengersTable.getModel();

        // Se o voo estiver vazio
        if (v != null) {

            // Apaga tudinho
            for (int i = model.getRowCount() - 1; i >= 0; i--) {
                model.removeRow(i);
            }

            for (Passagem t : v.getPassagems()) {
                Object row[] = new Object[2];
                row[0] = t.getPassageiro().getNome();
                row[1] = t.getAssento().toString();
                model.addRow(row);
            }
        }
    }

    /**
     * Limpa os campos pra deixar tudo bonitinho
     */
    private void clearFields() {
        List<Tupla<JTextField, String>> campos = new ArrayList<>();
        campos.add(new Tupla<>(searchTextField, searchFieldMessage));
        campos.add(new Tupla<>(flightNumberTextField, flightFieldMessage));
        campos.add(new Tupla<>(nameTextField, nameFieldMessage));
        campos.add(new Tupla<>(cpfTextField, cpfFieldMessage));

        // Manda essa classe fazer o trabalho grosso.
        TextFieldEffects.clearFields(campos);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        titleLabel = new javax.swing.JLabel();
        quitLabel = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        flightNumberTextField = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        flightsTable = new javax.swing.JTable();
        jLabel3 = new javax.swing.JLabel();
        saleLabel = new javax.swing.JLabel();
        updateLabel = new javax.swing.JLabel();
        nameTextField = new javax.swing.JTextField();
        cpfTextField = new javax.swing.JTextField();
        searchTextField = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        passengersTable = new javax.swing.JTable();
        jLabel4 = new javax.swing.JLabel();

        setBackground(new java.awt.Color(58, 58, 58));

        jPanel1.setBackground(new java.awt.Color(160, 160, 160));

        titleLabel.setFont(new java.awt.Font("Lucida Sans", 1, 16));
        titleLabel.setForeground(new java.awt.Color(255, 255, 255));
        titleLabel.setText("Tickets");

        quitLabel.setFont(new java.awt.Font("Lucida Sans", 1, 16));
        quitLabel.setForeground(new java.awt.Color(255, 255, 255));
        quitLabel.setText("X");
        quitLabel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                quitLabelMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                quitLabelMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                quitLabelMouseExited(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(titleLabel)
                .add(57, 57, 57)
                .add(quitLabel)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                .add(quitLabel)
                .add(titleLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 32, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );

        jPanel2.setOpaque(false);

        flightNumberTextField.setForeground(new java.awt.Color(119, 167, 243));
        flightNumberTextField.setText("N�mero do v�o");
        flightNumberTextField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                flightNumberTextFieldFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                flightNumberTextFieldFocusLost(evt);
            }
        });

        flightsTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "N�mero", "Aeronave", "Sa�da", "Origem", "Destino", "Vagas", "Ocupadas"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        flightsTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                flightsTableMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(flightsTable);

        jLabel3.setFont(new java.awt.Font("Lucida Sans", 2, 16));
        jLabel3.setForeground(new java.awt.Color(255, 255, 255));
        jLabel3.setText("V�os");

        saleLabel.setForeground(new java.awt.Color(255, 255, 255));
        saleLabel.setText("Vender");
        saleLabel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                saleLabelMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                saleLabelMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                saleLabelMouseExited(evt);
            }
        });

        updateLabel.setBackground(new java.awt.Color(132, 180, 254));
        updateLabel.setForeground(new java.awt.Color(255, 255, 255));
        updateLabel.setText("Atualizar");
        updateLabel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                updateLabelMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                updateLabelMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                updateLabelMouseExited(evt);
            }
        });

        nameTextField.setForeground(new java.awt.Color(119, 167, 243));
        nameTextField.setText("Nome");
        nameTextField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                nameTextFieldFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                nameTextFieldFocusLost(evt);
            }
        });

        cpfTextField.setForeground(new java.awt.Color(119, 167, 243));
        cpfTextField.setText("CPF");
        cpfTextField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                cpfTextFieldFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                cpfTextFieldFocusLost(evt);
            }
        });

        searchTextField.setForeground(new java.awt.Color(119, 167, 243));
        searchTextField.setText("Pesquisar por destino");
        searchTextField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                searchTextFieldFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                searchTextFieldFocusLost(evt);
            }
        });
        searchTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                searchTextFieldKeyReleased(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                        .add(jLabel3)
                        .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup()
                            .add(saleLabel)
                            .add(18, 18, 18)
                            .add(updateLabel)
                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(searchTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 158, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 673, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(flightNumberTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 138, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(nameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 138, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(cpfTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 138, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel3)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(searchTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(saleLabel)
                    .add(updateLabel))
                .add(18, 18, 18)
                .add(flightNumberTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(nameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(cpfTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(47, 47, 47))
        );

        jPanel3.setOpaque(false);

        passengersTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Passageiro", "Assento"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane2.setViewportView(passengersTable);

        jLabel4.setFont(new java.awt.Font("Lucida Sans", 2, 16));
        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
        jLabel4.setText("Lista de passageiros");

        org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
                    .add(jLabel4))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel4)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 346, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(13, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(layout.createSequentialGroup()
                        .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(18, 18, 18)
                        .add(jPanel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(jPanel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(96, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

private void quitLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_quitLabelMouseClicked
    main.Return();
    quitLabel.setForeground(Color.white);
}//GEN-LAST:event_quitLabelMouseClicked

private void updateLabelMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_updateLabelMouseEntered
    updateLabel.setForeground(new Color(132, 180, 254));
}//GEN-LAST:event_updateLabelMouseEntered

private void updateLabelMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_updateLabelMouseExited
    updateLabel.setForeground(Color.white);
}//GEN-LAST:event_updateLabelMouseExited

private void saleLabelMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_saleLabelMouseEntered
    saleLabel.setForeground(new Color(132, 180, 254));
}//GEN-LAST:event_saleLabelMouseEntered

private void saleLabelMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_saleLabelMouseExited
    saleLabel.setForeground(Color.white);
}//GEN-LAST:event_saleLabelMouseExited

private void quitLabelMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_quitLabelMouseEntered
    quitLabel.setForeground(new Color(61, 61, 61));
}//GEN-LAST:event_quitLabelMouseEntered

private void quitLabelMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_quitLabelMouseExited
    quitLabel.setForeground(Color.white);
}//GEN-LAST:event_quitLabelMouseExited

private void updateLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_updateLabelMouseClicked
    updateTable();
}//GEN-LAST:event_updateLabelMouseClicked

private void searchTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_searchTextFieldKeyReleased
    // Se o usuario precionar ENTER
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        JTextField field = (JTextField) evt.getSource();
        searchAndShow(field.getText().trim());
    }
}//GEN-LAST:event_searchTextFieldKeyReleased

private void saleLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_saleLabelMouseClicked
    submit();
}//GEN-LAST:event_saleLabelMouseClicked

private void searchTextFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_searchTextFieldFocusGained
    if (searchTextField.getText().equals(searchFieldMessage)) {
        TextFieldEffects.activeTextField((JTextField) evt.getSource());
    }
}//GEN-LAST:event_searchTextFieldFocusGained

private void searchTextFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_searchTextFieldFocusLost
    if (searchTextField.getText().equals("")) {
        TextFieldEffects.ociousTextField((JTextField) evt.getSource(), searchFieldMessage);
    }
}//GEN-LAST:event_searchTextFieldFocusLost

private void flightNumberTextFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_flightNumberTextFieldFocusGained
    if (flightNumberTextField.getText().equals(flightFieldMessage)) {
        TextFieldEffects.activeTextField((JTextField) evt.getSource());
    }
}//GEN-LAST:event_flightNumberTextFieldFocusGained

private void flightNumberTextFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_flightNumberTextFieldFocusLost
    if (flightNumberTextField.getText().equals("")) {
        TextFieldEffects.ociousTextField((JTextField) evt.getSource(), flightFieldMessage);
    }
}//GEN-LAST:event_flightNumberTextFieldFocusLost

private void nameTextFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_nameTextFieldFocusGained
    if (nameTextField.getText().equals(nameFieldMessage)) {
        TextFieldEffects.activeTextField((JTextField) evt.getSource());
    }
}//GEN-LAST:event_nameTextFieldFocusGained

private void nameTextFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_nameTextFieldFocusLost
    if (nameTextField.getText().equals("")) {
        TextFieldEffects.ociousTextField((JTextField) evt.getSource(), nameFieldMessage);
    }
}//GEN-LAST:event_nameTextFieldFocusLost

private void cpfTextFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_cpfTextFieldFocusGained
    if (cpfTextField.getText().equals(cpfFieldMessage)) {
        TextFieldEffects.activeTextField((JTextField) evt.getSource());
    }
}//GEN-LAST:event_cpfTextFieldFocusGained

private void cpfTextFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_cpfTextFieldFocusLost
    if (cpfTextField.getText().equals("")) {
        TextFieldEffects.ociousTextField((JTextField) evt.getSource(), cpfFieldMessage);
    }
}//GEN-LAST:event_cpfTextFieldFocusLost

    private void flightsTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_flightsTableMouseClicked
        loadPassengersTable();
    }//GEN-LAST:event_flightsTableMouseClicked
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField cpfTextField;
    private javax.swing.JTextField flightNumberTextField;
    private javax.swing.JTable flightsTable;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextField nameTextField;
    private javax.swing.JTable passengersTable;
    private javax.swing.JLabel quitLabel;
    private javax.swing.JLabel saleLabel;
    private javax.swing.JTextField searchTextField;
    private javax.swing.JLabel titleLabel;
    private javax.swing.JLabel updateLabel;
    // End of variables declaration//GEN-END:variables
    
    private MainUI main;
    private String searchFieldMessage = "Pesquisar por destino";
    private String flightFieldMessage = "Numero do voo";
    private String nameFieldMessage = "Nome";
    private String cpfFieldMessage = "CPF";
}
